package com.example.qjia.ui.activity;

import android.content.Intent;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.DatePicker;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.qjia.R;
import com.example.qjia.basic.BaseActivity;
import com.example.qjia.ui.fragment.SettingFragment;
import com.example.qjia.ui.fragment.SuggestionFragment;
import com.example.qjia.ui.fragment.UserMessageFragment;
import com.example.qjia.ui.fragment.VersionUpdateFragment;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

public class UserSetingActivity extends BaseActivity implements View.OnClickListener {

    private int currentFragmentId;
    private static final String TAG="UserSettingActivity";
    private LinearLayout back_ly;
    private TextView userSetting_Title;
    private FrameLayout fragmentContainer;
    private List<Fragment> fragments;
    private String[] titles;
    private FragmentManager fragmentManager;
    private UserMessageFragment userMessageFragment;
    private SettingFragment settingFragment;
    private VersionUpdateFragment versionUpdateFragment;
    private SuggestionFragment suggestionFragment;




    @Override
    protected int getLayoutResourceId() {
        return R.layout.activity_user_seting;
    }

    @Override
    protected void init() {
        back_ly=(LinearLayout)findViewById(R.id.back_ly);
        back_ly.setOnClickListener(this);
        userSetting_Title=(TextView)findViewById(R.id.userSetting_title);
        fragmentContainer=(FrameLayout)findViewById(R.id.fragment_container);
        fragments=new ArrayList<>();
        titles=new String[]{"用户信息","提示选项","版本更新","意见反馈"};
        if(userMessageFragment==null){
            userMessageFragment=UserMessageFragment.newInstance();
        } if(settingFragment==null){
            settingFragment=SettingFragment.newInstance();
        } if(versionUpdateFragment==null){
            versionUpdateFragment=VersionUpdateFragment.newInstance();
        } if(suggestionFragment==null){
            suggestionFragment=SuggestionFragment.newInstance();
        }
        fragments.add(userMessageFragment);
        fragments.add(settingFragment);
        fragments.add(versionUpdateFragment);
        fragments.add(suggestionFragment);


        Intent intent=getIntent();
        currentFragmentId=intent.getIntExtra("fragmentId",0);
        Log.w(TAG, "onCreate: currentFragmentId:"+currentFragmentId);


    }

    @Override
    protected void initView() {
        userSetting_Title.setText(titles[currentFragmentId-1]);
        fragmentManager=getSupportFragmentManager();
        FragmentTransaction fragmentTransaction=fragmentManager.beginTransaction();
        SettingFragment settingFragment=SettingFragment.newInstance();
        fragmentTransaction.add(R.id.fragment_container, fragments.get(currentFragmentId - 1),"settingFragment");
        fragmentTransaction.commit();


    }

    @Override
    public void onClick(View view) {
        finish();

    }
}
